//
//  GZSQLModelToolTest.m
//  GZSQLModelTool_Tests
//
//  Created by Guo Rui on 2018/1/25.
//  Copyright © 2018年 GR. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "GZSQLModelTool.h"
#import "GZStu.h"
#import "GZSQLModelProtocol.h"

@interface GZSQLModelToolTest : XCTestCase

@end

@implementation GZSQLModelToolTest

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testCreateTable {
    // This is an example of a functional test case.
    // Use XCTAssert and related functions to verify your tests produce the correct results.
    [GZSQLModelTool createTable:[GZStu class] uid:nil];
}

- (void)testIsRequired {
    BOOL isRequired = [GZSQLModelTool isTableRequireDataMigration:[GZStu class] uid:nil];
}

- (void)testTableDataMigration {
    BOOL ok = [GZSQLModelTool tableDataMigration:[GZStu class] uid:nil];
    XCTAssertTrue(ok);
}

- (void)testSaveOrUpdate {
    GZStu *stu = [[GZStu alloc] init];
    stu.number = 4;
    stu.name = @"zwz";
    stu.score = 12;
    stu.books = @[@"ios", @"java", @"python"];
    
    NSString *path = [[NSBundle bundleForClass:self.class] pathForResource:@"jj.png" ofType:nil];
    stu.data = [NSData dataWithContentsOfFile:path];
    BOOL ok = [GZSQLModelTool saveOrUpdateModel:stu uid:nil];
    XCTAssertTrue(ok);
}

- (void)testDeleteModel {
//    GZStu *stu = [[GZStu alloc] init];
//    stu.number = 1;
//
//    BOOL ok = [GZSQLModelTool deleteModel:stu uid:nil];
//    XCTAssertTrue(ok);
    
    BOOL ok = [GZSQLModelTool deleteClass:[GZStu class] condition:@"score < 50" uid:nil];
    XCTAssertTrue(ok);
}

- (void)testQueryModel {
    NSArray *models = [GZSQLModelTool queryAllModels:[GZStu class] uid:nil];
    NSLog(@"%@", models);
}

- (void)testPerformanceExample {
    // This is an example of a performance test case.
    [self measureBlock:^{
        // Put the code you want to measure the time of here.
    }];
}

@end
